package com.example.searchcenter.activity;

import java.util.ArrayList;
import java.util.HashMap;

import com.example.searchcenter.R;
import com.example.searchcenter.helper.ImageLoader;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.TextView;

@SuppressLint("InflateParams")
public class ActivitiesAdapter extends BaseAdapter implements Filterable {

	private Activity activity;
	private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader;
	
    public ActivitiesAdapter (Activity a, ArrayList<HashMap<String, String>> d)
    {
    	activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
        
    }
    
    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }
    
    public View getView(int position, View convertView, ViewGroup parent)
    {
    	View vi=convertView;
    	if(convertView==null)
    		vi = inflater.inflate(R.layout.list_item_activities, null);
    	
    	TextView id_activity = (TextView)vi.findViewById(R.id.id_activity);
    	TextView name = (TextView)vi.findViewById(R.id.name_activity);
    	TextView location = (TextView)vi.findViewById(R.id.location_activity);
    	TextView date_activity = (TextView)vi.findViewById(R.id.date_activity);
    	ImageView thumb_activity = (ImageView)vi.findViewById(R.id.list_image_activity);
    	
    	HashMap<String, String> activity = new HashMap<String, String>();
    	activity = data.get(position);
    	
    	// Setting all values in listview
    	id_activity.setText(activity.get(ActivitiesFragment.TAG_ID_ACTIVITY));
    	name.setText(activity.get(ActivitiesFragment.TAG_NAME));
    	location.setText("Địa điểm : "+activity.get(ActivitiesFragment.TAG_LOCATION));
    	date_activity.setText(activity.get(ActivitiesFragment.TAG_CREATEDATE));
    	
    	// Load thumbnail image of article
    	imageLoader.DisplayImage(activity.get(ActivitiesFragment.TAG_THUMBNAILIMAGEURL), thumb_activity);
    	
    	return vi;
    }
    
    @Override
	public Filter getFilter() {
		// TODO Auto-generated method stub
		return null;
    }
}
